#include <iostream>
#include <unordered_set>

// 求一个数每一位平方的和
int getResult(int n) {
    int result{};
    while (n) {
        int value = n % 10;
        result += value * value;
        n = n / 10;
    }

    return result;
}

bool isHappy(int n) {
    std::unordered_set<int> answers{};
    while (n != 1) {
        if (answers.find(n) != answers.end()) {
            return false;
        }

        answers.insert(n);
        n = getResult(n);
    }

    return true;
}

int main() {
    std::cout << std::boolalpha;
    std::cout << isHappy(2) << "\n";
    return 0;
}